var util = require('../../../utils/util.js')
var config = require('../../../utils/config.js')
var storeAPI = require('../../../utils/store.js')
var API_URL = config.API_URL
var app = getApp()
var page, loading;
var getGood = function (that) {
    if (loading) {
        return
    }
    loading = true;
    let params = {
        page: page
    }
    util.PRL(API_URL.collect_list, params)
        .then(res => {
            console.log(res)
            var loadingText;
            var collections;
            if (page == 1) {
                collections = new Array();
            } else {
                collections = that.data.collections;
            }
            collections = collections.concat(res.data.data.data);
            if (res.data.data.hasMore == 0) {
                loadingText = '没有更多了';
            } else {
                loadingText = '加载中...'
            }
            if (res.data.data.data.length != 0) {
                page++
            }
            that.setData({
                collections: collections,
                loadingText: loadingText
            })
            loading = false;
            my.hideLoading();
            my.stopPullDownRefresh();
        }).catch(res => {
            loading = false;
            my.hideLoading();
            my.stopPullDownRefresh();
        })
}

Page({
    data: {
        collections: [],
        loadingText: ''
    },
    onLoad: function (options) {
        // 页面初始化 options为页面跳转所带来的参数
        my.showLoading({
            title: '加载中...',
        })
        var that = this;
        page = 1;
        loading = false;
        getGood(that);
        setTimeout(my.hideLoading,1000)
    },
})